package serverside;

import java.sql.SQLException;
import java.util.Scanner;
import javax.swing.JOptionPane;

public class BillPayment extends Transaction {

    private Keypad keypad;
    private Scanner input;
    String tmp;

    public BillPayment(int _cardID, DatabasePack.BankDatabase atmBankDatabase, Screen atmScreen, Keypad atmKeypad) {
        super(_cardID, atmBankDatabase, atmScreen);
        keypad = atmKeypad;
        input = new Scanner(System.in);
    }

    @Override
    public void execute() {
        System.out.println("Transaction::BillPayment");
        DatabasePack.BankDatabase database = getBankDatabase();
        Screen screen = getScreen();

        screen.sendDataToClient("You can pay.");
        String[] list = ATM.separate(tmp = keypad.getInput());
        System.out.println("Transaction::BillPayment client sent: "
                + tmp);
        String result = database.bill_payment(getCardID(), list[0], Integer.parseInt(list[1]),
                Integer.parseInt(list[2]), Integer.parseInt(list[3]));
        screen.sendDataToClient(result);
        System.out.println("Transaction::BillPayment result: " + result
                + "\n");
    }

}
